//
//  NoticeFirstTrialViewController.swift
//  PropertyCommunity
//
//  Created by benwang on 2021/7/4.
//

import UIKit
import SnapKit
import JXSegmentedView

/// 公告初审
class NoticeFirstTrialViewController: UIViewController {

  let titles: [NoticeListType] = [.firtTrial, .retrial]
  let segmentedView = JXSegmentedView()
  let segmentedDataSource = JXSegmentedTitleDataSource()

  lazy var listContainerView = JXSegmentedListContainerView(dataSource: self)

  let sheetHandler = PTSheetHandle()

  override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    opacityNavigationBar(color: .designKit.background)

    title = "公告初审"
    view.backgroundColor = .designKit.background

    segmentedView.delegate = self
    view.addSubview(segmentedView)

    let filterView = R.nib.noticeFilterContentView(owner: self)!
    view.addSubview(filterView)

    segmentedDataSource.titles = titles.map { $0.rawValue }
    segmentedDataSource.isTitleColorGradientEnabled = true
    segmentedView.dataSource = self.segmentedDataSource
    segmentedView.backgroundColor = .designKit.background
    segmentedDataSource.titleSelectedColor = .designKit.accent

    let indicator = JXSegmentedIndicatorLineView()
    indicator.indicatorWidth = 42
    indicator.indicatorColor = .designKit.accent
    segmentedView.indicators = [indicator]

    segmentedView.listContainer = listContainerView
    view.addSubview(listContainerView)

    segmentedView.snp.makeConstraints { make in
      make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
      make.left.right.equalToSuperview()
      make.height.equalTo(36)
    }

    filterView.snp.makeConstraints { make in
      make.top.equalTo(segmentedView.snp.bottom)
      make.left.right.equalToSuperview()
      make.height.equalTo(44)
    }

    listContainerView.snp.makeConstraints { make in
      make.top.equalTo(filterView.snp.bottom)
      make.left.right.bottom.equalToSuperview()
    }
  }


  /*
   // MARK: - Navigation

   // In a storyboard-based application, you will often want to do a little preparation before navigation
   override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
   // Get the new view controller using segue.destination.
   // Pass the selected object to the new view controller.
   }
   */

}


extension NoticeFirstTrialViewController: JXSegmentedViewDelegate {
}

extension NoticeFirstTrialViewController: JXSegmentedListContainerViewDataSource {

  func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
    return segmentedDataSource.titles.count
  }

  func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {

    let vc = NoticeListViewController()
    vc.type = titles[index]
    return vc
  }
}
